Accusoft.PdfXpress7.ActiveX
Work with Security

PDF Xpress™ supports working with Security for Documents.

  • Once the Security Settings of a document have been modified, the document should be saved, and the PdfDocument should be destroyed before opening the original PDF again or before the saved document is opened.
  • If an invalid Owner Password is specified to the GetSecurity() method, an “An Invalid Owner Password was specified” error will occur.

The following is an example in which a secure PDF Document is opened and the Security Settings are queried (e.g., Permissions, EncryptMethod, User Password, Owner Password) by calling the GetSecurity() method.

VB6
Copy Code
Option Explicit
Dim pdf As New PdfXpress
Private Sub Command1_Click()
    pdf.Initialize
  
    Dim doc As New PdfDocument
    doc.SetParentControl pdf
    doc.OpenDocument "document.pdf", "user"
   
    Dim security As security
    Set security = doc.GetSecurity("")
   
    Dim commentingAllowed As PDF_PermissionStatus
    Dim changingTheDocumentAllowed As PDF_PermissionStatus
    Dim encryptMethod As PDF_EncryptMethod
   
    commentingAllowed = security.Commenting
    changingTheDocumentAllowed = security.ChangingTheDocument
    encryptMethod = security.encryptMethod
   
    pdf.Terminate
End Sub

The following is an example in which a secure PDF Document is opened and the Security Settings are queried by calling the GetSecurity() method and are then modified.

By passing the correct Owner Password as the parameter of the GetSecurity() method, the Security Settings obtained can be modified.

VB6
Copy Code
Option Explicit
Dim pdf As New PdfXpress
Private Sub Command1_Click()
    pdf.Initialize
  
    Dim doc As New PdfDocument
    doc.SetParentControl pdf
    doc.OpenDocument "document.pdf", "user"
   
    Dim security As security
    Set security = doc.GetSecurity("owner")
   
    security.ContentCopying = PDF_PermissionStatus.PDF_PermissionStatus_NotAllowed

    security.UserPassword = "accusoft"
    security.OwnerPassword = "pdf"
   
    Dim saveOptions As New saveOptions
    saveOptions.Linearized = True
    saveOptions.Overwrite = True
    saveOptions.FileName = "saved.pdf"
  
    doc.SaveDocument saveOptions
   
    pdf.Terminate
End Sub

The following is an example in which a secure PDF Document is opened and the Security Settings are removed by calling the RemoveSecurity() method.

By passing the correct Owner Password as the parameter of the GetSecurity() method, the Security Settings obtained can be modified.

VB6
Copy Code
Option Explicit
Dim pdf As New PdfXpress
Private Sub Command1_Click()
    pdf.Initialize
  
    Dim doc As New PdfDocument
    doc.SetParentControl pdf
    doc.OpenDocument "document.pdf", "user"
   
    doc.RemoveSecurity
   
    Dim saveOptions As New saveOptions
    saveOptions.Linearized = True
    saveOptions.Overwrite = True
    saveOptions.FileName = "saved.pdf"
  
    doc.SaveDocument saveOptions
   
    pdf.Terminate
End Sub

The following is an example in which a non-secure PDF document is opened and Security Settings are added by calling the AddSecurity() method.

An Owner Password must be specified when adding Security to a Document.

VB6
Copy Code
Option Explicit
Dim pdf As New PdfXpress
Private Sub Command1_Click()
    pdf.Initialize
  
    Dim doc As New PdfDocument
    doc.SetParentControl pdf
    doc.OpenDocument "document.pdf"
   
    Dim newSecurity As Security
    Set newSecurity = New Security
                   
    newSecurity.SetParentControl pdf
    newSecurity.OwnerPassword = "owner"
    newSecurity.HighResolutionPrinting = PDF_PermissionStatus_NotAllowed
   
    doc.AddSecurity newSecurity
   
    Dim saveOptions As New saveOptions
    saveOptions.Linearized = True
    saveOptions.Overwrite = True
    saveOptions.FileName = "saved.pdf"
  
    doc.SaveDocument saveOptions
   
    pdf.Terminate
End Sub

 

 


©2017. Accusoft Corporation. All Rights Reserved.

Send Feedback